<template>
  <div class="wrap-left-bottom">
    <div class="moudle-title">缺 陷 信 息【{{ totalNum }}】</div>
    <div :style="{ width: '100%', height: '100%' }">
      <LakerEcharts
        ref="myChartRightCenterRef"
        :option="dataOption"
        width="100%"
        height="100%"
        @chartOnclick="openTicketList"
      />
    </div>
    <el-dialog v-model="dialogTableVisible" :title="dialogTitle" width="90%">
      <LimList :ticketSta="ticketSta" />
    </el-dialog>
  </div>
</template>
<script>
import LakerEcharts from '@/components/lakerEcharts/index.vue'
import LimList from './LimList.vue'
import * as echarts from 'echarts'
import sppApi from '@/api/spp'

export default {
  name: 'SppRightCenter',
  components: { LakerEcharts, LimList },
  data() {
    return {
      dialogTableVisible: false,
      ticketSta: 0,
      dialogTitle: '工作票信息',
      totalNum: 0,
      dataOption: {
        backgroundColor: '',
        grid: {
          top: '10%',
          left: '3%',
          right: '4%',
          bottom: '10%',
          containLabel: true
        },
        yAxis: {
          type: 'value',
          max: 25,
          axisTick: {
            show: false
          },
          axisLine: {
            show: true,
            lineStyle: {
              color: '#363e83'
            }
          },
          splitLine: {
            show: true,
            lineStyle: {
              color: '#363e83 '
            }
          },
          axisLabel: {
            textStyle: {
              color: '#fff',
              fontWeight: 'normal',
              fontSize: '12'
            }
          }
        },
        xAxis: [
          {
            type: 'category',
            axisTick: {
              show: false
            },
            axisLine: {
              show: true,
              lineStyle: {
                color: '#363e83'
              }
            },
            axisLabel: {
              inside: false,
              // rotate: 60,
              textStyle: {
                color: '#fff',
                fontWeight: 'normal',
                fontSize: '11'
              }
            },
            data: ['职工', '外委', '访客']
          }
        ],
        series: [
          {
            type: 'bar',
            label: {
              show: true,
              position: 'top',
              color: 'greenyellow',
              fontWeight: 'normal',
              fontSize: '12'
            },
            itemStyle: {
              normal: {
                show: true,
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                  {
                    offset: 0,
                    color: 'rgb(46,200,207,1)'
                  },
                  {
                    offset: 1,
                    color: 'greenyellow'
                  }
                ]),
                borderRadius: 50,
                borderWidth: 0
              }
            },
            barWidth: '15',
            data: [8, 15, 10]
          }
        ]
      }
    }
  },
  mounted() {
    this.initLoadData()
  },
  methods: {
    openTicketList(param) {
      this.ticketSta = param.name
      this.dialogTableVisible = true
    },
    initLoadData() {
      sppApi.getTicketNumBySta().then((res) => {
        if (res.code === 200) {
          let serdata = []
          let serTitle = []
          let total = 0
          for (let i = 0; i < res.data.length; i++) {
            serTitle.push(res.data[i]['TICKET_TYPE'])
            serdata.push(res.data[i]['TICKET_NUM'])
            total = total + res.data[i]['TICKET_NUM']
          }
          this.totalNum = total
          this.dataOption = {
            xAxis: [{ data: serTitle }],
            series: [
              {
                data: serdata
              }
            ]
          }
        }
      })
    }
  }
}
</script>

<style scoped lang="scss">
.wrap-left-bottom {
  padding: 10px 10px;
  width: 100%;
  height: 100%;

  .moudle-title {
    color: #50e9ff;
    font-size: 16px;
    text-align: center;
  }

  #myChart-left-bottom {
    margin: 0 auto;
  }
}
</style>
